// var url = "http://mt1.google.cn/vt/lyrs=s&hl=zh-CN&x={x}&y={y}&z={z}&s=Gali";
var satellite = null;
let viewer = new Cesium.Viewer('cesiumContainer', {
  animation: false,//是否显示动画控件
  shouldAnimate: true,
  baseLayerPicker: false,
  // infoBox:false,
  geocoder: false, //是否显示地名查找控件
  navigationHelpButton: false,//是否显示帮助信息控件
  timeline: false, //是否显示时间线控件
  sceneModePicker: true, //是否显示投影方式控件
  imageryProvider: new Cesium.TileMapServiceImageryProvider({
    url: 'lib/Cesium/Assets/Textures/NaturalEarthII',
    fileExtension: "jpg"
  })
});
viewer.homeButton.viewModel.command.beforeExecute.addEventListener(function(e) {
  e.cancel = true;
  //你要飞的位置
  viewer.camera.flyTo({
    destination: Cesium.Cartesian3.fromDegrees(120.20, 20.7, 10000000)
  });
});
//设置初始位置,勿删
viewer.camera.setView({
  destination: Cesium.Cartesian3.fromDegrees(120.20, 20.7, 10000000)
});
//去掉大气渲染
viewer.scene.globe.showGroundAtmosphere = false;
//去掉左下角logo
viewer.cesiumWidget.creditContainer.style.display = "none";
var enetity = viewer.entities.add({
  name: '长春',
  position: Cesium.Cartesian3.fromDegrees(125.35, 43.88, 1000),
  billboard: {
    image: 'gltfModel/marker.png',
    horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
    scale: 0.3,
  },
  label: {
    text: '长春',
    scale:0.5,
    fillColor: Cesium.Color.BLACK
}
})
var enetity2 = viewer.entities.add({
  name: '大连',
  position: Cesium.Cartesian3.fromDegrees(121.62, 38.92, 1000),
  billboard: {
    image: 'gltfModel/marker.png',
    horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
    scale: 0.3,
  },
  label: {
    text: '大连',
    scale:0.5,
    fillColor: Cesium.Color.BLACK
  }
})
var enetity3 = viewer.entities.add({
  name: '石家庄',
  position: Cesium.Cartesian3.fromDegrees(114.48, 38.03, 1000),
  billboard: {
    image: 'gltfModel/marker.png',
    horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
    scale: 0.3,
  },
  label: {
    text: '石家庄',
    scale:0.5,
    fillColor: Cesium.Color.BLACK
  }
})
var enetity4 = viewer.entities.add({
  name: '包头',
  position: Cesium.Cartesian3.fromDegrees(109.84, 40.657, 1000),
  billboard: {
    label:'',
    image: 'gltfModel/marker.png',
    horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
    scale: 0.3,
  },
  label: {
    text: '包头',
    scale:0.5,
    fillColor: Cesium.Color.BLACK
  }
})
var enetity5 = viewer.entities.add({
  name: '青海湖',
  position: Cesium.Cartesian3.fromDegrees(100.2, 36.9, 1000),
  billboard: {
    image: 'gltfModel/marker.png',
    horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
    scale: 0.3,
  },
  label: {
    text: '青海湖',
    scale:0.5,
    fillColor: Cesium.Color.BLACK
  }
})
var enetity6 = viewer.entities.add({
  name: '南通',
  position: Cesium.Cartesian3.fromDegrees(120.88, 31.98, 1000),
  billboard: {
    image: 'gltfModel/marker.png',
    horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
    scale: 0.3,
  },
  label: {
    text: '南通',
    scale:0.5,
    fillColor: Cesium.Color.BLACK
  }
})
var enetity7 = viewer.entities.add({
  name: '广州',
  position: Cesium.Cartesian3.fromDegrees(113.23, 23.16, 1000),
  billboard: {
    image: 'gltfModel/marker.png',
    horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
    scale: 0.3,
  },
  label: {
    text: '广州',
    scale:0.5,
    fillColor: Cesium.Color.BLACK
  }
})
var enetity8 = viewer.entities.add({
  name: '南宁',
  position: Cesium.Cartesian3.fromDegrees(108.33, 22.84, 1000),
  billboard: {
    image: 'gltfModel/marker.png',
    horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
    scale: 0.3,
  },
  label: {
    text: '南宁',
    scale:0.5,
    fillColor: Cesium.Color.BLACK
  }
})
var enetity9 = viewer.entities.add({
  name: '呼伦贝尔',
  position: Cesium.Cartesian3.fromDegrees(119.76, 49.22, 1000),
  billboard: {
    image: 'gltfModel/marker.png',
    horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
    scale: 0.3,
  },
  label: {
    text: '呼伦贝尔',
    scale:0.5,
    fillColor: Cesium.Color.BLACK
  }
})
var enetity10 = viewer.entities.add({
  name: '敦煌',
  position: Cesium.Cartesian3.fromDegrees(94.71, 40.13, 1000),
  billboard: {
    image: 'gltfModel/marker.png',
    horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
    scale: 0.3,
  },
  label: {
    text: '敦煌',
    scale:0.5,
    fillColor: Cesium.Color.BLACK
  }
})
var ellipsoid = viewer.scene.globe.ellipsoid;
var start = viewer.clock.startTime;
var clock = viewer.clock;
var cylinderEntity = viewer.entities.add({
  cylinder: {
    HeightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
    length: 600000,
    topRadius: 0,
    bottomRadius: 600000 / 4,
    material: Cesium.Color.RED.withAlpha(.4),
    outline: !0,
    numberOfVerticalLines: 0,
    outlineColor: Cesium.Color.RED.withAlpha(.8)
  }
});

var property;
viewer.dataSources.add(Cesium.CzmlDataSource.load("czml/GAOFEN1.czml")).then(function (dataSource) {
  satellite = dataSource.entities.getById("");
  property = new Cesium.SampledPositionProperty();
  for (var ind = 0; ind < 292; ind++) {
    var time = Cesium.JulianDate.addSeconds(clock.startTime, 300 * ind, new Cesium.JulianDate());
    var position = satellite.position.getValue(time);
    var cartographic = viewer.scene.globe.ellipsoid.cartesianToCartographic(position);
    var lat = Cesium.Math.toDegrees(cartographic.latitude),
      lng = Cesium.Math.toDegrees(cartographic.longitude),
      hei = cartographic.height / 1.9;
    property.addSample(time, Cesium.Cartesian3.fromDegrees(lng, lat, hei));
  }
  cylinderEntity.position = property;
  cylinderEntity.position.setInterpolationOptions({ //设定位置的插值算法
    interpolationDegree: 5,
    interpolationAlgorithm: Cesium.LagrangePolynomialApproximation
  });

});